/* Measuring Time to Compliance with International Reparations: 
   Evidence from the Inter-American System of Human Rights
   Aníbal Pérez-Liñán
   University of Notre Dame 
   ORCiD: 0000-0003-4109-2725
*/

** Install the DETC package 

net install  detc, from("https://aperezli.github.io/stata-detc/") replace
net describe detc

** Table 2

* Get data matrix (Table 1) 
  net get detc
  sysuse detcdata, clear
* Discrete-time logit (Equation 1)
  logit C M I t
  predict ypc
* Compute ARC and DETC
  detc ypc reparation t

** Table 3

* Create data matrix
clear
set obs 2
gen Case = _n
 expand 2
 gen Rep = _n
 replace Rep = Rep + (Case - 1)*2
  expand 4
  bysort Case Rep: gen t = _n - 1
forvalues i = 1/3 {
    gen     ypc`i' = .01
	replace ypc`i' = .99 if t == `i'
}  
* Estimate ARC and DETC for each scenario
  detc ypc1 Rep t
  detc ypc2 Rep t
  detc ypc3 Rep t
  
** Tables 4 and 5

* Replication data for Pérez-Liñán, Schenoni, and Morrison (2023)
* Originally available at https://doi.org/10.7910/DVN/66TP69
use "0_iacthr.dta", clear

* Replicate model for Table 4
mecloglog y_any i.rtype2 c.t##c.t##c.t##c.t##c.t##c.t  || cowcode: || casecode:
 predict ypc_any if e(sample)

* Compute ARC for the sample
 detc ypc_any repcode t  
 
* Create Table 5 
* Note: in the original article, Table 2 aggregates first by reparation, then type 
 collapse (mean) ypc_any arc_ypc_any (first) rtype2, by(repcode)
 collapse (mean) ypc_any arc_ypc_any               , by(rtype2)
 gen etc_any  = 1/ypc_any      // ETC
 gen etc_arc  = 1/arc_ypc_any  // DETC
  * Format table
  label values rtype2 rtype2
  format %8.1f etc_any etc_arc
  format %8.3f ypc_any arc_ypc_any
  sort etc_any
  label var ypc_any "YPC"
  label var etc_any "ETC (synchronic)"
  label var arc_ypc_any "ARC"
  label var etc_arc "ETC (diachronic)"
  label var rtype2 "Type of Reparation"